package com.witframework.web.tag.tooltip;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class TooltipTag extends BodyTagSupport
{
  private static final String ID = "tlttgcj2004";
  private static final String MARK = "tlttgcjjs2004";
  private static final String PREFIX = "tlttgc";
  private static final String DEF_HELPSTYLE = "position:absolute;visibility:hidden;background-color:yellow;padding:3px;border-style:solid;border-color:black;border-width:1px;margin-top:5px;";
  private String help = null;
  private String helpStyle = null;
  private String helpClassName = null;
  private String helpWidth = null;
  private String text = null;
  private String textStyle = null;
  private String textClassName = null;
  private boolean cond = true;

  public void setCond(boolean paramBoolean)
  {
    this.cond = paramBoolean;
  }

  public boolean getCond()
  {
    return this.cond;
  }

  public void setHelp(String paramString)
  {
    this.help = paramString;
  }

  public String getHelp()
  {
    return this.help;
  }

  public void setHelpStyle(String paramString)
  {
    this.helpStyle = paramString;
  }

  public String getHelpStyle()
  {
    return this.helpStyle;
  }

  public void setHelpClassName(String paramString)
  {
    this.helpClassName = paramString;
  }

  public String getHelpClassName()
  {
    return this.helpClassName;
  }

  public void setText(String paramString)
  {
    this.text = paramString;
  }

  public String getText()
  {
    return this.text;
  }

  public void setTextStyle(String paramString)
  {
    this.textStyle = paramString;
  }

  public String getTextStyle()
  {
    return this.textStyle;
  }

  public void setTextClassName(String paramString)
  {
    this.textClassName = paramString;
  }

  public String getTextClassName()
  {
    return this.textClassName;
  }

  public void setHelpWidth(String paramString)
  {
    this.helpWidth = paramString;
  }

  public String getHelpWidth()
  {
    return this.helpWidth;
  }

  public int doStartTag()
    throws JspException
  {
    return 2;
  }

  public int doAfterBody()
    throws JspException
  {
    BodyContent localBodyContent = getBodyContent();
    if (localBodyContent != null)
      localBodyContent.clearBody();
    return 0;
  }

  public int doEndTag()
    throws JspException
  {
    StringBuffer localStringBuffer = new StringBuffer("");
    int i = 0;
    if (this.text == null)
    {
      dropData();
      return 6;
    }
    if (this.help == null)
      i = 1;
    else if (this.help.length() == 0)
      i = 1;
    else if ("NULL".equalsIgnoreCase(this.help))
      i = 1;
    if ((i != 0) || (!(this.cond)))
    {
      localStringBuffer.append(getPureText());
    }
    else
    {
      if (this.pageContext.getAttribute("tlttgcjjs2004", 2) == null)
      {
        this.pageContext.setAttribute("tlttgcjjs2004", "yes", 2);
        localStringBuffer.append("\n<script language=\"JavaScript\" type=\"text/javascript\">\n");
        localStringBuffer.append("function tooltipVisibility(id,vis)\n");
        localStringBuffer.append("{var dddd;\n");
        localStringBuffer.append(" if(document.all) ");
        localStringBuffer.append("  {dddd=document.all[id].style;\n");
        localStringBuffer.append("if (dddd) ");
        localStringBuffer.append("dddd.visibility = vis ? \"visible\":\"hidden\";\n");
        localStringBuffer.append("  } else\n");
        localStringBuffer.append(" if(document.layers) ");
        localStringBuffer.append("  {dddd=document.layers[id];\n");
        localStringBuffer.append("   if (dddd) ");
        localStringBuffer.append("   dddd.visibility = vis ? \"show\":\"hide\";\n");
        localStringBuffer.append("  } else\n");
        localStringBuffer.append(" if (document.getElementById) {");
        localStringBuffer.append(" dddd=document.getElementById(id).style; ");
        localStringBuffer.append(" if (dddd) ");
        localStringBuffer.append(" dddd.visibility = vis ? \"visible\":\"hidden\"; }\n");
        localStringBuffer.append("return false;");
        localStringBuffer.append("}\n");
        localStringBuffer.append("</script>\n");
      }
      localStringBuffer.append("<div");
      if (this.textClassName != null)
        localStringBuffer.append(" class=\"" + this.textClassName + "\"");
      if (this.textStyle != null)
        localStringBuffer.append(" style=\"" + this.textStyle + "\"");
      String str = getTooltipId();
      localStringBuffer.append(" onmouseover=\"tooltipVisibility('");
      localStringBuffer.append(str);
      localStringBuffer.append("',true);\"");
      localStringBuffer.append(" onmouseout=\"tooltipVisibility('");
      localStringBuffer.append(str);
      localStringBuffer.append("',false);\"");
      localStringBuffer.append(">");
      localStringBuffer.append(this.text);
      localStringBuffer.append("</div>");
      localStringBuffer.append("<span id=\"");
      localStringBuffer.append(str);
      localStringBuffer.append("\"");
      if ((this.helpStyle == null) && (this.helpClassName == null))
        this.helpStyle = "position:absolute;visibility:hidden;background-color:yellow;padding:3px;border-style:solid;border-color:black;border-width:1px;margin-top:5px;";
      if (this.helpClassName != null)
      {
        localStringBuffer.append(" class=\"");
        localStringBuffer.append(this.helpClassName);
        localStringBuffer.append("\"");
      }
      if (this.helpStyle != null)
      {
        localStringBuffer.append(" style=\"");
        localStringBuffer.append(this.helpStyle);
        localStringBuffer.append("\"");
      }
      localStringBuffer.append(" onmouseover=\"tooltipVisibility('");
      localStringBuffer.append(str);
      localStringBuffer.append("',true);\"");
      localStringBuffer.append(" onmouseout=\"tooltipVisibility('");
      localStringBuffer.append(str);
      localStringBuffer.append("',false);\"");
      localStringBuffer.append(">");
      localStringBuffer.append("<table border=\"0\"");
      if (this.helpWidth != null)
        localStringBuffer.append(" width=\"" + this.helpWidth + "\"");
      localStringBuffer.append("><tr><td>");
      localStringBuffer.append(this.help);
      localStringBuffer.append("</td></tr></table>");
      localStringBuffer.append("</span>");
    }
    try
    {
      this.pageContext.getOut().write(localStringBuffer.toString());
    }
    catch (Exception localException)
    {
      throw new JspException("tooltipTag: could not save body " + localException.toString());
    }
    dropData();
    return 6;
  }

  private void dropData()
  {
    this.help = null;
    this.helpStyle = null;
    this.helpClassName = null;
    this.helpWidth = null;
    this.text = null;
    this.textStyle = null;
    this.textClassName = null;
    this.cond = true;
  }

  public void release()
  {
    dropData();
  }

  private String getPureText()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    if ((this.textStyle == null) && (this.textClassName == null))
    {
      localStringBuffer.append(this.text);
    }
    else
    {
      localStringBuffer.append("<div");
      if (this.textClassName != null)
        localStringBuffer.append(" class=\"" + this.textClassName + "\"");
      if (this.textStyle != null)
        localStringBuffer.append(" style=\"" + this.textStyle + "\"");
      localStringBuffer.append(">");
      localStringBuffer.append(this.text);
      localStringBuffer.append("</div>");
    }
    return localStringBuffer.toString();
  }

  private String getTooltipId()
  {
    Integer localInteger = (Integer)this.pageContext.getAttribute("tlttgcj2004", 2);
    if (localInteger == null)
    {
      this.pageContext.setAttribute("tlttgcj2004", new Integer(2), 2);
      return "tlttgc1";
    }
    this.pageContext.setAttribute("tlttgcj2004", new Integer(localInteger.intValue() + 1), 2);
    return "tlttgc" + localInteger;
  }
}